/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.button;

import org.rails.extjs.BoxComponent;
import org.rails.extjs.Option;
import org.rails.extjs.Template;
import org.rails.extjs.javascript.Function;
import org.rails.extjs.menu.Menu;

public class Button extends BoxComponent {
	
	public static final String ARROWALIGN_RIGHT = "right";
	public static final String ARROWALIGN_BOTTOM = "bottom";

	public static final String ICON_ALIGN_TOP = "top";
	public static final String ICON_ALIGN_RIGHT = "right";
	public static final String ICON_ALIGN_BOTTOM = "bottom";
	public static final String ICON_ALIGN_LEFT = "left";
	
	public static final String SCALE_SMALL = "small";
	public static final String SCALE_MEDIUM = "medium";
	public static final String SCALE_LARGE = "large";

	
	
	public Button() {
		super();
	}

	public Button(String text,String icon,Function handler) {
		super();
		setText(text);
		setIcon(icon);
		setHandler(handler);
	}
	
	public Button(Option configOption){
		super(configOption);
	}
	
	public void setAllowDepress(Boolean allowDepress){
		addOption("allowDepress", allowDepress);
	}
	
	public Boolean isAllowDepress(){
		return getBoolean("allowDepress",false);
	}
	
	public void setArrowAlign(String arrowAlign){
		addOption("arrowAlign", arrowAlign);
	}
	
	public String getArrowAlign(){
		return getString("arrowAlign",ARROWALIGN_RIGHT);
	}
	
	public void setButtonSelector(String buttonSelector){
		addOption("buttonSelector", buttonSelector);
	}
	
	public String getButtonSelector(){
		return getString("buttonSelector", "button:first-child");
	}
	
	public void setClickEvent(String clickEvent){
		addOption("clickEvent", clickEvent);
	}
	
	public String getClickEvent(){
		return getString("clickEvent", "click");
	}
	
	public void setEnableToggle(Boolean enableToggle){
		addOption("enableToggle", enableToggle);
	}
	
	public Boolean isEnableToggle(){
		return getBoolean("enableToggle",false);
	}
	
	public void setHandleMouseEvents(Boolean handleMouseEvents){
		addOption("handleMouseEvents", handleMouseEvents);
	}
	
	public Boolean isHandleMouseEvents(){
		return getBoolean("handleMouseEvents",true);
	}
	
	public void setHandler(Function handler){
		addOption("handler", handler);
	}
	
	public Function getHandler(){
		return (Function)getOption("handler");
	}

	public void setIcon(String icon){
		addOption("icon",icon);
	}
	
	public String getIcon(){
		return getString("icon","");
	}
	
	public void setIconAlign(String iconAlign){
		addOption("iconAlign", iconAlign);
	}
	
	public String getIconAlign(){
		return getString("iconAlign", ICON_ALIGN_LEFT);
	}
	
	public void setIconCls(String iconCls){
		addOption("iconCls", iconCls);
	}
	
	public String getIconCls(){
		return getString("iconCls","");
	}
	
	public void setMenu(Menu menu){
		addOption("menu",menu);
	}
	
	public Menu getMenu(){
		return (Menu)getOption("menu");
	}
	
	public void setMenuAlign(String menuAlign){
		addOption("menuAlign", menuAlign);
	}
	
	public String getMenuAlign(){
		return getString("menuAlign","tl-bl?");
	}
	
	public void setMinWidth(Integer minWidth){
		addOption("minWidth", minWidth);
	}
	
	public Integer getMinWidth(){
		return getInteger("minWidth", 0);
	}
	
	public void setOverflowText(String overflowText){
		addOption("overflowText", overflowText);
	}
	
	public String getOverflowText(){
		return getString("overflowText","");
	}
	
	public void setPressed(Boolean pressed){
		addOption("pressed", pressed);
	}
	
	public Boolean isPressed(){
		return getBoolean("pressed",false);
	}
	
	public void setRepeat(Boolean repeat){
		addOption("repeat", repeat);
	}
	
	public Boolean isRepeat(){
		return getBoolean("repeat",false);
	}
	
	public void setScale(String scale){
		addOption("scale", scale);
	}
	
	public String getScale(){
		return getString("scale",SCALE_SMALL);
	}
	
	public void setTabIndex(Integer tabIndex){
		addOption("tabIndex",tabIndex);
	}
	
	public Integer getTabIndex(){
		return getInteger("tabIndex",0);
	}
	
	public void setTemplate(Template template){
		addOption("template", template);
	}
	
	public Template getTemplate(){
		return (Template)getOption("template");
	}
	
	public void setText(String text){
		addOption("text", text);
	}
	
	public String getText(){
		return getString("text","");
	}
	
	public void setToggleGroup(String toggleGroup){
		addOption("toggleGroup", toggleGroup);
	}
	
	public String getToggleGroup(){
		return getString("toggleGroup","");
	}
	
	public void setToggleHandler(Function toggleHandler){
		addOption("toggleHandler", toggleHandler);
	}
	
	public Function getToggleHandler(){
		return (Function)getOption("toggleHandler");
	}
	
	public void setTooltip(String tooltip){
		addOption("tooltip", tooltip);
	}
	
	public String getTooltip(){
		return getString("tooltip","");
	}
	
	public void setTooltipType(String tooltipType){
		addOption("tooltipType",tooltipType);
	}
	
	public String getTooltipType(){
		return getString("tooltipType","");
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.Button(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
